package ch.usi.inf.pf2.editor;

import java.awt.Color;

import ch.usi.inf.pf2.Sheet;

/**
 * MultipleChangeCellColor is useful to change the color of 
 * more cells.
 * 
 * @author Ebrisa Savina Mastrodicasa
 */

public class MultipleChangeCellColor extends CellManagement
{
	private ChangeCellColor[][] toColor;

	
	/**
	 * Create a ChangeCellColor for more cells.
	 * @param s The sheet where the multiple copying is performed.
	 * @param rowIndex The rows of the selected cells.
	 * @param columnIndex The columns of the selected cells.
	 * @param newColor The color to be applied to the selected cells.
	 */
	public MultipleChangeCellColor(Sheet s, int[] rowIndexes, int[] columnIndexes, Color newColor)
	{
		toColor = new ChangeCellColor[rowIndexes.length][columnIndexes.length];
		for(int i=0; i<rowIndexes.length; i++)
			  for(int j=0; j<columnIndexes.length; j++)
				 toColor[i][j]=new ChangeCellColor(s, rowIndexes[i]+1, columnIndexes[j]+1, newColor); 
	}
	
	
	/**
	 * Apply the ChangeCellColor to all the selected cells.
	 */
	public void evaluate() {
		for(int i = 0; i < toColor.length; i++)
			for(int j = 0; j < toColor[i].length; j++)
			{
				toColor[i][j].evaluate();
			}
	}

	
	/**
	 * Restore the previous color of the selected cells.
	 */
	public void restore() {
		for(int i=0; i<toColor.length; i++)
			  for(int j=0; j<toColor[i].length; j++)
				 toColor[i][j].restore();
	}


}
